/*给定一个字符串，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。
*
* 输入："Let's take LeetCode contest"
* 输出："s'teL ekat edoCteeL tsetnoc"
* */

package plan_study.fourth;

import java.util.Arrays;

public class leetcode557 {

    public static void main(String[] args) {

        leetcode557 obj = new leetcode557();
        String s = "Let's take LeetCode contest";
        System.out.println(obj.reverseWords(s));
    }

    public String reverseWords(String s){

        int len = s.length();
        String[] str = s.split(" ");
        String res = "";
        for (int i = 0;i < str.length;i++){
            str[i] = swap(str[i]);
        }
        for (int i = 0;i < str.length;i++){
            res += str[i] + " ";
        }
        return res.substring(0, res.length() - 1);
    }

    public String swap(String s){

        int len = s.length();
        String rev = "";
        for (int i = 0;i < len;i++){
            rev = s.charAt(i) + rev;
        }
        return rev;
    }
}
